Skip to content

Darling analysis: the parameter sensitivity fact and drill-down keep each plan's newest row without sorting the whole window (#9492) - #9497

Open
erikdarlingdata wants to merge 6 commits into
devfrom
fix/9492-newest-row-aggregate
Open

erikdarlingdata wants to merge 6 commits into
devfrom
fix/9492-newest-row-aggregate

Conversation

@erikdarlingdata

@erikdarlingdata erikdarlingdata commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Claude posting for Erik Darling.

What changed

The parameter sensitivity fact (PgFactCollector.ParameterSensitivitySql) and its drill-down (PgDrillDownCollector.ParameterSensitiveSql) found each plan's newest row by numbering every row of the window with ROW_NUMBER() ... ORDER BY collection_time DESC. That sorts every chunk's rows, holds each sort until the merge ends, and picks an arbitrary row when two rows of one key share the newest time.

Both reads now group by the same key the PARTITION BY used (database_name, query_hash, query_plan_hash) and take max(ARRAY[...]) of an array that starts with the row's collection time (epoch microseconds) and collection_id, then the fields. Arrays compare element by element, so the largest array is the newest row, and on a tied time the row with the larger collection_id. Each field is read back by position, and each keeps its old output type. A NULL field after the (time, id) pair never decides the winner and comes back NULL. NULL key parts group together, as they did under PARTITION BY. Every WHERE condition, the parameters and their order, the final ORDER BY and the reply are unchanged. The only behaviour change: on two rows of one key at the newest time, the larger collection_id now wins (before, it was arbitrary).

  • Fact: max(ARRAY[...]) over v_query_stats, then a newest_rows step that reads the fields back, then the same filter, SELECT and ORDER BY as before.
  • Drill-down: the same aggregate over query_stats, then has_inline_text and query_text_digest come from LEFT JOIN LATERAL on query_stats by server_id, the winner's collection_time and collection_id, LIMIT 1. The lookup runs only for plans that pass the rough filter.

PlanAdvisorySql and the plan regression statement are untouched.

Field type check

collect.query_stats columns, from the migration ladder:

  • collection_id is bigint NOT NULL and collection_time is timestamp NOT NULL, so the leading pair is never NULL.
  • In the array: collection_time and creation_time (both timestamp without time zone, so epoch microseconds round trip exactly), collection_id, execution_count, min_worker_time, max_worker_time, min_grant_kb, max_grant_kb, min_spills, max_spills (all bigint, nullable).
  • By lookup: has_inline_text (a boolean) and query_text_digest (bytea), drill-down only.

Tests

New live class ParameterSensitivityNewestRowLiveTests, run against both reads over the same seeded rows. The seeded plans:

  • Two rows at the newest time plus an older row with the largest id and the largest figures. The larger id wins and every figure comes from it: worker ratio, grant ratio, spill divergence, creation time to the microsecond. For the drill-down also the execution count, has_inline_text (false, though the losing row has inline text) and the digest.
  • A newest row with NULL grant and spill fields over an older row that has values. The fields come back NULL and the older values are not used.
  • An older row with larger values under a newest row with smaller ones. The newest row's figures are reported.
  • An older row that passes the filter under a newest row that does not. The plan is not reported.
  • NULL database, query hash and plan hash. One group, with the newest row's figures.

Two existing guards needed a small change, not a looser rule. The scans that check every FROM target resolves to a view, table or CTE now skip the FROM inside EXTRACT(epoch FROM col), which names a column. The drill-down text comparison builds its old-shape query by text replacement, and that replacement now matches the lateral lookup's column.

Revert proof: with both reads put back to the old SQL, both new tests fail (Expected: 100, Actual: 20): the old read keeps the smaller-id row of the tied pair. With the new SQL both pass.

EXPLAIN

The test store has no TimescaleDB, so there are no chunks and the per-chunk sort under a merge append cannot appear or be shown absent here. Seeded 240,000 rows (500 plans, 480 snapshots, 5 days) and ran EXPLAIN (ANALYZE, BUFFERS) over a 7 day window. Top nodes:

Fact:
Sort (actual rows=462) Sort Method: quicksort Memory: 68kB
  -> Subquery Scan on latest
       -> HashAggregate Group Key: database_name, query_hash, query_plan_hash  Batches: 1  Memory Usage: 689kB  Rows Removed by Filter: 38
            -> Seq Scan on query_stats (actual rows=240000)
Execution Time: 155 ms

Drill-down:
Sort (actual rows=462) Sort Method: quicksort Memory: 79kB
  -> Nested Loop Left Join
       -> HashAggregate Group Key: database_name, query_hash, query_plan_hash  Batches: 1  Memory Usage: 689kB
            -> Seq Scan on query_stats (actual rows=240000)
       -> Limit -> Index Scan using idx_query_stats_time on query_stats q (loops=462, one probe per plan)
Execution Time: 164 ms

No sort sits under the aggregate. The chunked plan (aggregate over a merge append with no per-chunk sort) needs a TimescaleDB store and is the re-time the issue's "Done when" asks for after the next nightly.

Runs

  • Release build of Darling.Tests, 0 errors, 0 warnings.
  • pre-push.sh: Guard Darling.Tests 5004 passed, 0 failed. Guard Lite.Tests 1248 passed, 0 failed. GATE STOP: the selection was the whole suite (darling 3239, lite 533), and no selected class ran.
  • Classes run on top of that, all green: ParameterSensitivityNewestRowLiveTests, *ParameterSensitiv*, PgFactCollectorTests, PlanRegressionReadShapeTests, ServerLocalRowConversionTests, StatementDrillDownTextFetchLiveTests, FactsNameQueries*, FactThresholdsTests, CreationTimeClockFrameDisciplineTests, AnalysisPlanAdvisoryGzReadTests, DarlingAnalysisPipelineTests, DrillDownSqlTests, DrillDownDopProvenance*, QueryHighDopStaleMaxDopParityTests, *PlanRegression* (188, 4 skipped), ConsumedTimestampFrameDisciplineTests, DarlingReadsUseOnlyStoreViewsTests, PgTargetFactCollectorTests, PgTargetAnomalyTests, LatestValueLookback*, BadActorFactDrillDownAgreement*.

Considered, not added: a tiebreak on the drill-down's final ORDER BY (unchanged on purpose, it is outside this change).

Left as a draft until a field check of the 7 day timing on a chunked store.

Fixes #9492

Release note: the parameter sensitivity checks read a week of history about three times faster, and pick the same row every time when two rows share the newest collection time.

Round 1 fixes

  • The drill-down's inline text read (ParameterSensitiveInlineTextSql) now orders by collection_time DESC, collection_id DESC. On two rows of one plan at the newest time it returns the text of the larger collection_id, the same row the ranking keeps. Its doc comment no longer mentions the old row numbering.
  • New test TheDrillDownInlineText_OnATiedTime_ComesFromTheLargerCollectionId_AgainstDevPostgres: two rows of one plan share the newest time, both carry inline text, the texts differ, and the smaller id is inserted first. The read must return the larger id's text. The seeded plan has a worker ratio of 2, so the ranking does not report it and the other tests in the class are unchanged. The class's seed and read plumbing now share one helper.
  • Proof: with the new ORDER BY term removed, the new test fails (the other two tests in the class pass). With the term back, all pass.
  • Runs on a live dev Postgres: *ParameterSensitivityNewestRow*, *StatementDrillDownTextFetch*, *PgDrillDown*, *ParameterSensitiv* (23 tests, 0 failed). Release build, 0 errors.
  • Considered, not added: an index for the lateral probe (inline comment near line 394). On a production-sized store the probe costs a few milliseconds and the rough filter leaves a handful of rows to probe, so the probe is unchanged.

@erikdarlingdata
erikdarlingdata marked this pull request as ready for review November 24, 2026 17:05
FROM query_stats AS q
WHERE q.server_id = $1
AND q.collection_time = n.newest_time
AND q.collection_id = n.newest_id

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance (non-blocking, needs a check on a real store): this probe has only server_id, collection_time and collection_id to work with, so the planner uses idx_query_stats_time (server_id, collection_time). The PR body's EXPLAIN shows that index. On that index, each probe reads every query_stats row the server wrote in the winning collection and fetches each one from the heap to test collection_id. On the 500-plan seed that is 500 rows per probe. On a busy server it is thousands of rows per collection, multiplied by every plan that passes the rough filter. On a TimescaleDB store the probe can also land in a compressed chunk.

One option: add AND q.query_hash = n.query_hash when n.query_hash is not null. That lets idx_query_stats_server_hash_time (server_id, query_hash, collection_time DESC) narrow each probe to a few rows. NULL-hash keys would need their own arm, because = drops them. Either way, the per-probe cost belongs in the chunked-store re-time the body defers to the nightly run.

@claude

claude Bot commented Nov 24, 2026

Copy link
Copy Markdown

Correctness: the drill-down's inline-text read still breaks ties arbitrarily (Darling/PerformanceMonitor.Darling.Analysis/PgDrillDownCollector.Queries.cs:459. This line is unchanged, so it can't take an inline comment.)

ParameterSensitiveSql now keeps the larger collection_id when a plan has two rows at the newest time, and reads has_inline_text and query_text_digest from that row. The next read, ParameterSensitiveInlineTextSql, picks its row with DISTINCT ON (...) ORDER BY q.database_name, q.query_hash, q.query_plan_hash, q.collection_time DESC. It has no collection_id tiebreak. On a tie it returns whichever tied row comes first, and that may not be the row the ranking kept.

Ties are common. Every row of one collection is written with the same collection_time. Several dm_exec_query_stats entries often share database, query_hash and query_plan_hash, because the same statement shape appears under different sql_handles with different literals. In that case the drill-down can print the figures of one row next to the text of a sibling. The text is either the sibling's own inline text, or the sibling's dimension text through the COALESCE.

This contradicts two statements:

  • the method's doc comment at :432-435: "Each plan's row is the one that read ranked … (its rn = 1)". There is no longer an rn, and the row isn't the same one on a tie.
  • the release note: "pick the same row every time when two rows share the newest collection time."

Fix (one line, and it matches Lite's ORDER BY collection_time DESC, collection_id DESC at Lite/Analysis/DrillDownCollector.Queries.cs:315):

ORDER BY q.database_name, q.query_hash, q.query_plan_hash, q.collection_time DESC, q.collection_id DESC

Also update the doc comment so it no longer refers to rn = 1.

Coverage: the new ParameterSensitivityNewestRowLiveTests tie case doesn't reach this read. Its winner has no inline text (has_inline_text is false), so ReadParameterSensitiveInlineTextAsync never runs. A test that would fail on this defect: a tied pair where both rows carry different inline text and the larger id is inserted first. Then assert the drill-down's query_text is the larger-id row's text. This can go through StatementDrillDownTextFetchLiveTests' oracle or a new case in the new class.

claude[bot]
claude Bot previously requested changes Nov 24, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CHANGES REQUESTED

Claims

  • VERIFIED — Both reads group by database_name, query_hash, query_plan_hash and take max(ARRAY[...]), starting with the collection time in epoch µs and then collection_id — PgFactCollector.QueryPerf.cs:232-246, PgDrillDownCollector.Queries.cs:328-342.
  • VERIFIED — Every field keeps its old output type — every array member is bigint (PerformanceMonitor.Collectors/QueryStatsCollector.cs:991-1021), and creation_time is rebuilt as timestamp at PgFactCollector.QueryPerf.cs:258 / PgDrillDownCollector.Queries.cs:356. The store is PG17/18, where extract returns numeric, so the round trip is exact.
  • VERIFIED — The leading (time, id) pair is never NULL — PgSchemaGenerator.cs:75 (collection_id bigint NOT NULL), and the window's range predicate on collection_time excludes NULL anyway. Ids are per row (CollectionIdGenerator.Next() per COPY row, DarlingCollectorRunner.StoreWriteAndWatermarks.cs:747).
  • VERIFIED — NULL key parts form one group, as they did under PARTITION BY — standard GROUP BY semantics; the NULL-key case in ParameterSensitivityNewestRowLiveTests.SeedRows.
  • VERIFIED — The WHERE conditions, parameters and their order, the final ORDER BY and the SELECT list are unchanged — the hunks; the reader's ordinals in PgDrillDownCollector.Queries.cs:555-575 still line up with the final SELECT at :403-427.
  • VERIFIED — The drill-down's has_inline_text and query_text_digest come from a LEFT JOIN LATERAL on query_stats by server_id, the winning time and the winning id, with LIMIT 1 — PgDrillDownCollector.Queries.cs:383-397.
  • VERIFIED — PlanAdvisorySql and the plan regression statement are untouched — gh pr diff --name-only and the hunk ranges.
  • VERIFIED — The new live class seeds the five listed cases and asserts each one against both reads — ParameterSensitivityNewestRowLiveTests.cs SeedRows / AssertNewestRows.
  • VERIFIED — Two existing guards were adjusted: the EXTRACT(... FROM skip, and the oracle's text replacement now matches t.has_inline_text — DarlingAnalysisPipelineTests.cs:289, PgFactCollectorTests.cs:307, StatementDrillDownTextFetchLiveTests.cs:296.
  • UNVERIFIED — The lateral lookup runs only for plans that pass the rough filter — this depends on where the planner places the filter. It needs an EXPLAIN on a real store. The body's loops=462 is consistent with it.
  • UNVERIFIED — The revert proof (Expected: 100, Actual: 20 on the old SQL) — needs a live Postgres run.
  • UNVERIFIED — The EXPLAIN figures and the release note's "about three times faster" — needs a live, chunked TimescaleDB store. The body defers this to the nightly run.
  • UNVERIFIED — Release build with 0 warnings, the pre-push guard counts and the listed class runs — needs a build and a test run.
  • REFUTED — "pick the same row every time when two rows share the newest collection time" (release note) and "The only behaviour change: … the larger collection_id now wins" — the drill-down's inline text comes from ParameterSensitiveInlineTextSql, whose DISTINCT ON orders by collection_time DESC alone (PgDrillDownCollector.Queries.cs:459). On a tie it can return text from a row other than the one the ranking kept.

Riskiest lines

  1. Darling/PerformanceMonitor.Darling.Analysis/PgDrillDownCollector.Queries.cs:459 — the inline-text read has no collection_id tiebreak, so on a tie its text can come from a different row than the drill-down's figures — UNCOVERED. The new tie case's winner has no inline text, so this read never runs in it.
  2. Darling/PerformanceMonitor.Darling.Analysis/PgDrillDownCollector.Queries.cs:394 — the lateral lookup by winning time and id. A wrong key would give the winner a different row's text flag and digest — covered by ParameterSensitivityNewestRowLiveTests.TheDrillDown_KeepsEachPlansNewestRow_AndReadsItsTextFieldsFromThatRow_AgainstDevPostgres (asserts the winner's has_inline_text false and its digest).
  3. Darling/PerformanceMonitor.Darling.Analysis/PgFactCollector.QueryPerf.cs:232 — the array's element order decides which row is newest, and the positions read back at :257-264 must match it — covered by ParameterSensitivityNewestRowLiveTests.TheFact_KeepsEachPlansNewestRow_AndTheLargerIdOnATiedTime_AgainstDevPostgres (asserts tie winner, older-row exclusion, NULL fields, and the creation time to the microsecond).

Traps near this diff

  • "MAX(max_dop) grouped by query_hash is the highest DOP ANY plan for that statement text ever ran at … An aggregate across plans needs provenance (which plan, when) or the newest plan's reading." — does not apply — the max is over a whole-row array led by (time, id), so every field comes from one row (the newest), and the group includes query_plan_hash (PgFactCollector.QueryPerf.cs:232-251).
  • "Lite and Darling ship in parity (CONTRIBUTING's two-store rule): a fix to one SKU's reader, tool, alert or description without the counterpart's is a finding" — does not apply — Lite already breaks ties on collection_id DESC (Lite/Analysis/DuckDbFactCollector.QueryPerf.cs:264, Lite/Analysis/DrillDownCollector.Queries.cs:315). This PR brings Darling's two ranking reads in line with it. The remaining gap at PgDrillDownCollector.Queries.cs:459 is reported under Divergence.
  • "Ruling (#5833): tests are load-bearing. … Never add one, and never answer a trap with a test that reads source text" — does not apply — no new source-reading guard is added. The two edits (DarlingAnalysisPipelineTests.cs:289, PgFactCollectorTests.cs:307) adjust existing scans, and the new class is a behaviour test.
  • "A test that reads the clock twice measures the CI scheduler" — does not apply — ParameterSensitivityNewestRowLiveTests reads LiveClock.Now() once into the static WindowEnd, and Window() derives both ends from it.
  • "A 'latest snapshot' read anchored on = (SELECT MAX(collection_time) …) must project the anchor so the payload can say WHEN" — does not apply — these are per-plan newest-row reads feeding a fact and a drill-down, not a snapshot payload anchored on one global time (PgFactCollector.QueryPerf.cs:228-251).
  • ".gitattributes says text=auto eol=crlf … A diff that touches every line of a file is a line-ending conversion until proven otherwise" — does not apply — every hunk is region-scoped (for example PgDrillDownCollector.Queries.cs @@ -306,61 +306,98 @@).

Divergence (blind read vs PR body)

  • The body says that on a tie the drill-down now keeps the same row every time. The ranking read does. The inline-text read that supplies the printed text (PgDrillDownCollector.Queries.cs:459) still orders by collection_time DESC alone. Its doc comment (:432-435) still describes the row as "its rn = 1", and rn no longer exists. Fix: add , q.collection_id DESC to that ORDER BY and add a tie test where both tied rows carry different inline text. Details are in the top-level comment.
  • The body's EXPLAIN shows each lateral probe served by idx_query_stats_time (server_id, collection_time). That index makes each probe read every row of the winning collection for the server, and the body doesn't discuss that cost. It is fine on a 500-plan seed, but unmeasured on busy or compressed stores. This is non-blocking and covered in an inline comment on :394.

Reviewer checklist

  • On a chunked TimescaleDB store, run EXPLAIN (ANALYZE, BUFFERS) on both reads over a 7-day window. Confirm there's no per-chunk sort under the aggregate, and check the lateral's per-probe rows and buffers on a busy server.
  • Run ParameterSensitivityNewestRowLiveTests and StatementDrillDownTextFetchLiveTests against a live Postgres (DARLING_TEST_PG) after the tiebreak fix.
  • Do a release build of Darling.Tests and confirm there are no new warnings.

claude[bot]
claude Bot previously requested changes Nov 24, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CHANGES REQUESTED

Claims

  • VERIFIED — Both reads group by database_name, query_hash, query_plan_hash and take max(ARRAY[...]), starting with the collection time in epoch µs and then collection_id — PgFactCollector.QueryPerf.cs:232-246, PgDrillDownCollector.Queries.cs:328-342.
  • VERIFIED — Every field keeps its old output type — every array member is bigint (PerformanceMonitor.Collectors/QueryStatsCollector.cs:991-1021), and creation_time is rebuilt as timestamp at PgFactCollector.QueryPerf.cs:258 / PgDrillDownCollector.Queries.cs:356. The store is PG17/18, where extract returns numeric, so the round trip is exact.
  • VERIFIED — The leading (time, id) pair is never NULL — PgSchemaGenerator.cs:75 (collection_id bigint NOT NULL), and the window's range predicate on collection_time excludes NULL anyway. Ids are per row (CollectionIdGenerator.Next() per COPY row, DarlingCollectorRunner.StoreWriteAndWatermarks.cs:747).
  • VERIFIED — NULL key parts form one group, as they did under PARTITION BY — standard GROUP BY semantics; the NULL-key case in ParameterSensitivityNewestRowLiveTests.SeedRows.
  • VERIFIED — The WHERE conditions, parameters and their order, the final ORDER BY and the SELECT list are unchanged — the hunks; the reader's ordinals in PgDrillDownCollector.Queries.cs:555-575 still line up with the final SELECT at :403-427.
  • VERIFIED — The drill-down's has_inline_text and query_text_digest come from a LEFT JOIN LATERAL on query_stats by server_id, the winning time and the winning id, with LIMIT 1 — PgDrillDownCollector.Queries.cs:383-397.
  • VERIFIED — PlanAdvisorySql and the plan regression statement are untouched — gh pr diff --name-only and the hunk ranges.
  • VERIFIED — The new live class seeds the five listed cases and asserts each one against both reads — ParameterSensitivityNewestRowLiveTests.cs SeedRows / AssertNewestRows.
  • VERIFIED — Two existing guards were adjusted: the EXTRACT(... FROM skip, and the oracle's text replacement now matches t.has_inline_text — DarlingAnalysisPipelineTests.cs:289, PgFactCollectorTests.cs:307, StatementDrillDownTextFetchLiveTests.cs:296.
  • UNVERIFIED — The lateral lookup runs only for plans that pass the rough filter — this depends on where the planner places the filter. It needs an EXPLAIN on a real store. The body's loops=462 is consistent with it.
  • UNVERIFIED — The revert proof (Expected: 100, Actual: 20 on the old SQL) — needs a live Postgres run.
  • UNVERIFIED — The EXPLAIN figures and the release note's "about three times faster" — needs a live, chunked TimescaleDB store. The body defers this to the nightly run.
  • UNVERIFIED — Release build with 0 warnings, the pre-push guard counts and the listed class runs — needs a build and a test run.
  • REFUTED — "pick the same row every time when two rows share the newest collection time" (release note) and "The only behaviour change: … the larger collection_id now wins" — the drill-down's inline text comes from ParameterSensitiveInlineTextSql, whose DISTINCT ON orders by collection_time DESC alone (PgDrillDownCollector.Queries.cs:459). On a tie it can return text from a row other than the one the ranking kept.

Riskiest lines

  1. Darling/PerformanceMonitor.Darling.Analysis/PgDrillDownCollector.Queries.cs:459 — the inline-text read has no collection_id tiebreak, so on a tie its text can come from a different row than the drill-down's figures — UNCOVERED. The new tie case's winner has no inline text, so this read never runs in it.
  2. Darling/PerformanceMonitor.Darling.Analysis/PgDrillDownCollector.Queries.cs:394 — the lateral lookup by winning time and id. A wrong key would give the winner a different row's text flag and digest — covered by ParameterSensitivityNewestRowLiveTests.TheDrillDown_KeepsEachPlansNewestRow_AndReadsItsTextFieldsFromThatRow_AgainstDevPostgres (asserts the winner's has_inline_text false and its digest).
  3. Darling/PerformanceMonitor.Darling.Analysis/PgFactCollector.QueryPerf.cs:232 — the array's element order decides which row is newest, and the positions read back at :257-264 must match it — covered by ParameterSensitivityNewestRowLiveTests.TheFact_KeepsEachPlansNewestRow_AndTheLargerIdOnATiedTime_AgainstDevPostgres (asserts tie winner, older-row exclusion, NULL fields, and the creation time to the microsecond).

Traps near this diff

  • "MAX(max_dop) grouped by query_hash is the highest DOP ANY plan for that statement text ever ran at … An aggregate across plans needs provenance (which plan, when) or the newest plan's reading." — does not apply — the max is over a whole-row array led by (time, id), so every field comes from one row (the newest), and the group includes query_plan_hash (PgFactCollector.QueryPerf.cs:232-251).
  • "Lite and Darling ship in parity (CONTRIBUTING's two-store rule): a fix to one SKU's reader, tool, alert or description without the counterpart's is a finding" — does not apply — Lite already breaks ties on collection_id DESC (Lite/Analysis/DuckDbFactCollector.QueryPerf.cs:264, Lite/Analysis/DrillDownCollector.Queries.cs:315). This PR brings Darling's two ranking reads in line with it. The remaining gap at PgDrillDownCollector.Queries.cs:459 is reported under Divergence.
  • "Ruling (#5833): tests are load-bearing. … Never add one, and never answer a trap with a test that reads source text" — does not apply — no new source-reading guard is added. The two edits (DarlingAnalysisPipelineTests.cs:289, PgFactCollectorTests.cs:307) adjust existing scans, and the new class is a behaviour test.
  • "A test that reads the clock twice measures the CI scheduler" — does not apply — ParameterSensitivityNewestRowLiveTests reads LiveClock.Now() once into the static WindowEnd, and Window() derives both ends from it.
  • "A 'latest snapshot' read anchored on = (SELECT MAX(collection_time) …) must project the anchor so the payload can say WHEN" — does not apply — these are per-plan newest-row reads feeding a fact and a drill-down, not a snapshot payload anchored on one global time (PgFactCollector.QueryPerf.cs:228-251).
  • ".gitattributes says text=auto eol=crlf … A diff that touches every line of a file is a line-ending conversion until proven otherwise" — does not apply — every hunk is region-scoped (for example PgDrillDownCollector.Queries.cs @@ -306,61 +306,98 @@).

Divergence (blind read vs PR body)

  • The body says that on a tie the drill-down now keeps the same row every time. The ranking read does. The inline-text read that supplies the printed text (PgDrillDownCollector.Queries.cs:459) still orders by collection_time DESC alone. Its doc comment (:432-435) still describes the row as "its rn = 1", and rn no longer exists. Fix: add , q.collection_id DESC to that ORDER BY and add a tie test where both tied rows carry different inline text. Details are in the top-level comment.
  • The body's EXPLAIN shows each lateral probe served by idx_query_stats_time (server_id, collection_time). That index makes each probe read every row of the winning collection for the server, and the body doesn't discuss that cost. It is fine on a 500-plan seed, but unmeasured on busy or compressed stores. This is non-blocking and covered in an inline comment on :394.

Reviewer checklist

  • On a chunked TimescaleDB store, run EXPLAIN (ANALYZE, BUFFERS) on both reads over a 7-day window. Confirm there's no per-chunk sort under the aggregate, and check the lateral's per-probe rows and buffers on a busy server.
  • Run ParameterSensitivityNewestRowLiveTests and StatementDrillDownTextFetchLiveTests against a live Postgres (DARLING_TEST_PG) after the tiebreak fix.
  • Do a release build of Darling.Tests and confirm there are no new warnings.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: LGTM

Claims

  • VERIFIED — The inline-text read now breaks a tie on the newest time by collection_id DESC, the same row the ranking keeps — PgDrillDownCollector.Queries.cs:459 adds q.collection_id DESC to the DISTINCT ON ORDER BY.
  • VERIFIED — A new live test seeds two rows at the same newest time, both with inline text, and asserts the larger id's text is returned — ParameterSensitivityNewestRowLiveTests.cs TheDrillDownInlineText_OnATiedTime_ComesFromTheLargerCollectionId_AgainstDevPostgres. The larger id (-94_920_140) is inserted last, so insertion order does not decide it. Its ratio of 2 keeps it out of the ranking reads.
  • VERIFIED — The test refactor (WithSeededStoreAsync) leaves the existing reads unchanged — the ordinal mapping moved into the callback unchanged.
  • VERIFIED — The covering-index test now seeds from t.Start.AddHours(2), so the rows stay in the window when the hour turns — QueryFleetSummaryCoveringIndexLiveTests.cs:153. This is test-only.

Riskiest lines

  1. PgDrillDownCollector.Queries.cs:459 — the tie-break in the DISTINCT ON ordering — covered by TheDrillDownInlineText_OnATiedTime_ComesFromTheLargerCollectionId_AgainstDevPostgres (it needs DARLING_TEST_PG and skips without it).
  2. ParameterSensitivityNewestRowLiveTests.cs:~203 — the WithSeededStoreAsync extraction, which carries the shared seeding and cleanup — covered by the existing newest-row tests that call it.
  3. QueryFleetSummaryCoveringIndexLiveTests.cs:153 — the seed window shifted by 2h — UNCOVERED, and test-only.

Traps near this diff

  • No trap checked in detail for this light-tier follow-up. The change is a SQL ORDER BY tie-break plus tests, and it adds no new query shape. — does not apply — PgDrillDownCollector.Queries.cs:459.

Divergence (blind read vs PR body)

None found in this follow-up range. I did not run gh pr view for this pass.

Reviewer checklist

  • Run the new live test against a dev Postgres with DARLING_TEST_PG set. A read-only tree cannot run it.

@github-actions
github-actions Bot dismissed stale reviews from claude[bot] and claude[bot] November 24, 2026 17:20

Superseded by claude[bot]'s LGTM on 5bd5c9e: #9497 (review)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant